﻿using CSharpDesign.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace CSharpDesign.BLL
{
    public class XiuGaiSPLeiBieService
    {
        /// <summary>
        /// 根据分类ID获取分类名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetCategoryName(string id)
        {
            string name = "";
            SqlConnection con = new SqlConnection(SqlHelper.connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand("select  * from ShangPinFenLei where id=" + id, con);//从数据库中选择数据
            SqlDataReader sdr = cmd.ExecuteReader();//读数据
            if (sdr.Read())
                name = Convert.ToString(sdr["name"]);

            con.Close();
            return name;
        }
        
        /// <summary>
        /// 修改类别名称
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        public static void UpadteCategory(string id,string name)
        {
            SqlConnection con = new SqlConnection(SqlHelper.connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "update ShangPinFenLei set name=@name where id=@id";
            
            cmd.Parameters.Add("@name", SqlDbType.VarChar);
            cmd.Parameters.Add("@id", SqlDbType.Int);
            cmd.Parameters["@id"].Value = id;
            cmd.Parameters["@name"].Value = name;

            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
}